

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="zh-CN" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="zh-CN" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>wukong &mdash; wukong-robot 1.2.0 文档</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../_static/jquery.js"></script>
        <script type="text/javascript" src="../_static/underscore.js"></script>
        <script type="text/javascript" src="../_static/doctools.js"></script>
        <script type="text/javascript" src="../_static/language_data.js"></script>
        <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home"> wukong-robot
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">wukong-robot</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="index.html">模块代码</a> &raquo;</li>
        
      <li>wukong</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>wukong 源代码</h1><div class="highlight"><pre>
<span></span><span class="c1"># -*- coding: utf-8-*-</span>
<span class="kn">from</span> <span class="nn">snowboy</span> <span class="k">import</span> <span class="n">snowboydecoder</span>
<span class="kn">from</span> <span class="nn">robot</span> <span class="k">import</span> <span class="n">config</span><span class="p">,</span> <span class="n">utils</span><span class="p">,</span> <span class="n">constants</span><span class="p">,</span> <span class="n">logging</span><span class="p">,</span> <span class="n">statistic</span><span class="p">,</span> <span class="n">Player</span>
<span class="kn">from</span> <span class="nn">robot.Updater</span> <span class="k">import</span> <span class="n">Updater</span>
<span class="kn">from</span> <span class="nn">robot.ConfigMonitor</span> <span class="k">import</span> <span class="n">ConfigMonitor</span>
<span class="kn">from</span> <span class="nn">robot.Conversation</span> <span class="k">import</span> <span class="n">Conversation</span>
<span class="kn">from</span> <span class="nn">server</span> <span class="k">import</span> <span class="n">server</span>
<span class="kn">from</span> <span class="nn">watchdog.observers</span> <span class="k">import</span> <span class="n">Observer</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">signal</span>
<span class="kn">import</span> <span class="nn">hashlib</span>
<span class="kn">import</span> <span class="nn">fire</span>
<span class="kn">import</span> <span class="nn">urllib3</span>
<span class="n">urllib3</span><span class="o">.</span><span class="n">disable_warnings</span><span class="p">(</span><span class="n">urllib3</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">InsecureRequestWarning</span><span class="p">)</span>

<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

<div class="viewcode-block" id="Wukong"><a class="viewcode-back" href="../wukong.html#wukong.Wukong">[文档]</a><span class="k">class</span> <span class="nc">Wukong</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

    <span class="n">_profiling</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="n">_dev</span> <span class="o">=</span> <span class="kc">False</span>
    
<div class="viewcode-block" id="Wukong.init"><a class="viewcode-back" href="../wukong.html#wukong.Wukong.init">[文档]</a>    <span class="k">def</span> <span class="nf">init</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">global</span> <span class="n">conversation</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">detector</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_interrupted</span> <span class="o">=</span> <span class="kc">False</span>        
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;&#39;&#39;</span>
<span class="s1">********************************************************</span>
<span class="s1">*          wukong-robot - 中文语音对话机器人           *</span>
<span class="s1">*          (c) 2019 潘伟洲 &lt;m@hahack.com&gt;              *</span>
<span class="s1">*     https://github.com/wzpan/wukong-robot.git        *</span>
<span class="s1">********************************************************</span>

<span class="s1">            如需退出，可以按 Ctrl-4 组合键。</span>

<span class="s1">&#39;&#39;&#39;</span><span class="p">)</span>
        
        <span class="n">config</span><span class="o">.</span><span class="n">init</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_conversation</span> <span class="o">=</span> <span class="n">Conversation</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_profiling</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_conversation</span><span class="o">.</span><span class="n">say</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{}</span><span class="s1"> 你好！试试对我喊唤醒词叫醒我吧&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;first_name&#39;</span><span class="p">,</span> <span class="s1">&#39;主人&#39;</span><span class="p">)),</span> <span class="kc">True</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_observer</span> <span class="o">=</span> <span class="n">Observer</span><span class="p">()</span>
        <span class="n">event_handler</span> <span class="o">=</span> <span class="n">ConfigMonitor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_conversation</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_observer</span><span class="o">.</span><span class="n">schedule</span><span class="p">(</span><span class="n">event_handler</span><span class="p">,</span> <span class="n">constants</span><span class="o">.</span><span class="n">CONFIG_PATH</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_observer</span><span class="o">.</span><span class="n">schedule</span><span class="p">(</span><span class="n">event_handler</span><span class="p">,</span> <span class="n">constants</span><span class="o">.</span><span class="n">DATA_PATH</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_observer</span><span class="o">.</span><span class="n">start</span><span class="p">()</span></div>

    <span class="k">def</span> <span class="nf">_signal_handler</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">signal</span><span class="p">,</span> <span class="n">frame</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_interrupted</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="n">utils</span><span class="o">.</span><span class="n">clean</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_observer</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">_detected_callback</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">utils</span><span class="o">.</span><span class="n">is_proper_time</span><span class="p">():</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;勿扰模式开启中&#39;</span><span class="p">)</span>
            <span class="k">return</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_conversation</span><span class="o">.</span><span class="n">isRecording</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;正在录音中，跳过&#39;</span><span class="p">)</span>
            <span class="k">return</span>
        <span class="n">Player</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">constants</span><span class="o">.</span><span class="n">getData</span><span class="p">(</span><span class="s1">&#39;beep_hi.wav&#39;</span><span class="p">))</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;开始录音&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_conversation</span><span class="o">.</span><span class="n">interrupt</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_conversation</span><span class="o">.</span><span class="n">isRecording</span> <span class="o">=</span> <span class="kc">True</span><span class="p">;</span>

    <span class="k">def</span> <span class="nf">_do_not_bother_on_callback</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;/do_not_bother/hotword_switch&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="n">utils</span><span class="o">.</span><span class="n">do_not_bother</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="n">Player</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">constants</span><span class="o">.</span><span class="n">getData</span><span class="p">(</span><span class="s1">&#39;off.wav&#39;</span><span class="p">))</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;勿扰模式打开&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_do_not_bother_off_callback</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;/do_not_bother/hotword_switch&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="n">utils</span><span class="o">.</span><span class="n">do_not_bother</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="n">Player</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">constants</span><span class="o">.</span><span class="n">getData</span><span class="p">(</span><span class="s1">&#39;on.wav&#39;</span><span class="p">))</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;勿扰模式关闭&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_interrupt_callback</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_interrupted</span>

<div class="viewcode-block" id="Wukong.run"><a class="viewcode-back" href="../wukong.html#wukong.Wukong.run">[文档]</a>    <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">init</span><span class="p">()</span>

        <span class="c1"># capture SIGINT signal, e.g., Ctrl+C</span>
        <span class="n">signal</span><span class="o">.</span><span class="n">signal</span><span class="p">(</span><span class="n">signal</span><span class="o">.</span><span class="n">SIGINT</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_signal_handler</span><span class="p">)</span>

        <span class="c1"># site</span>
        <span class="n">server</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_conversation</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>

        <span class="n">statistic</span><span class="o">.</span><span class="n">report</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">initDetector</span><span class="p">()</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;初始化离线唤醒功能失败&#39;</span><span class="p">)</span>
            <span class="k">pass</span></div>

<div class="viewcode-block" id="Wukong.initDetector"><a class="viewcode-back" href="../wukong.html#wukong.Wukong.initDetector">[文档]</a>    <span class="k">def</span> <span class="nf">initDetector</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">detector</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">terminate</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;/do_not_bother/hotword_switch&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
            <span class="n">models</span> <span class="o">=</span> <span class="p">[</span>
                <span class="n">constants</span><span class="o">.</span><span class="n">getHotwordModel</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;hotword&#39;</span><span class="p">,</span> <span class="s1">&#39;wukong.pmdl&#39;</span><span class="p">)),</span>
                <span class="n">constants</span><span class="o">.</span><span class="n">getHotwordModel</span><span class="p">(</span><span class="n">utils</span><span class="o">.</span><span class="n">get_do_not_bother_on_hotword</span><span class="p">()),</span>
                <span class="n">constants</span><span class="o">.</span><span class="n">getHotwordModel</span><span class="p">(</span><span class="n">utils</span><span class="o">.</span><span class="n">get_do_not_bother_off_hotword</span><span class="p">())</span>
            <span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">models</span> <span class="o">=</span> <span class="n">constants</span><span class="o">.</span><span class="n">getHotwordModel</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;hotword&#39;</span><span class="p">,</span> <span class="s1">&#39;wukong.pmdl&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">detector</span> <span class="o">=</span> <span class="n">snowboydecoder</span><span class="o">.</span><span class="n">HotwordDetector</span><span class="p">(</span><span class="n">models</span><span class="p">,</span> <span class="n">sensitivity</span><span class="o">=</span><span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;sensitivity&#39;</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">))</span>
        <span class="c1"># main loop</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;/do_not_bother/hotword_switch&#39;</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
                <span class="n">callbacks</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_detected_callback</span><span class="p">,</span>
                             <span class="bp">self</span><span class="o">.</span><span class="n">_do_not_bother_on_callback</span><span class="p">,</span>
                             <span class="bp">self</span><span class="o">.</span><span class="n">_do_not_bother_off_callback</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">callbacks</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_detected_callback</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">start</span><span class="p">(</span><span class="n">detected_callback</span><span class="o">=</span><span class="n">callbacks</span><span class="p">,</span>
                                <span class="n">audio_recorder_callback</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_conversation</span><span class="o">.</span><span class="n">converse</span><span class="p">,</span>
                                <span class="n">interrupt_check</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_interrupt_callback</span><span class="p">,</span>
                                <span class="n">silent_count_threshold</span><span class="o">=</span><span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;silent_threshold&#39;</span><span class="p">,</span> <span class="mi">15</span><span class="p">),</span>
                                <span class="n">recording_timeout</span><span class="o">=</span><span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;recording_timeout&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span> <span class="o">*</span> <span class="mi">4</span><span class="p">,</span>
                                <span class="n">sleep_time</span><span class="o">=</span><span class="mf">0.03</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">terminate</span><span class="p">()</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s1">&#39;离线唤醒机制初始化失败：</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">e</span><span class="p">))</span></div>

<div class="viewcode-block" id="Wukong.md5"><a class="viewcode-back" href="../wukong.html#wukong.Wukong.md5">[文档]</a>    <span class="k">def</span> <span class="nf">md5</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">password</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">hashlib</span><span class="o">.</span><span class="n">md5</span><span class="p">(</span><span class="n">password</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">()</span></div>

<div class="viewcode-block" id="Wukong.update"><a class="viewcode-back" href="../wukong.html#wukong.Wukong.update">[文档]</a>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">updater</span> <span class="o">=</span> <span class="n">Updater</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">updater</span><span class="o">.</span><span class="n">update</span><span class="p">()</span></div>

<div class="viewcode-block" id="Wukong.fetch"><a class="viewcode-back" href="../wukong.html#wukong.Wukong.fetch">[文档]</a>    <span class="k">def</span> <span class="nf">fetch</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">updater</span> <span class="o">=</span> <span class="n">Updater</span><span class="p">()</span>
        <span class="n">updater</span><span class="o">.</span><span class="n">fetch</span><span class="p">()</span></div>

<div class="viewcode-block" id="Wukong.restart"><a class="viewcode-back" href="../wukong.html#wukong.Wukong.restart">[文档]</a>    <span class="k">def</span> <span class="nf">restart</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s1">&#39;程序重启...&#39;</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">detector</span><span class="o">.</span><span class="n">terminate</span><span class="p">()</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="n">python</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">executable</span>
        <span class="n">os</span><span class="o">.</span><span class="n">execl</span><span class="p">(</span><span class="n">python</span><span class="p">,</span> <span class="n">python</span><span class="p">,</span> <span class="o">*</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span></div>

<div class="viewcode-block" id="Wukong.profiling"><a class="viewcode-back" href="../wukong.html#wukong.Wukong.profiling">[文档]</a>    <span class="k">def</span> <span class="nf">profiling</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;性能调优&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_profiling</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">run</span><span class="p">()</span></div>

<div class="viewcode-block" id="Wukong.dev"><a class="viewcode-back" href="../wukong.html#wukong.Wukong.dev">[文档]</a>    <span class="k">def</span> <span class="nf">dev</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;使用测试环境&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_dev</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">run</span><span class="p">()</span></div></div>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">wukong</span> <span class="o">=</span> <span class="n">Wukong</span><span class="p">()</span>
        <span class="n">wukong</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">fire</span><span class="o">.</span><span class="n">Fire</span><span class="p">(</span><span class="n">Wukong</span><span class="p">)</span>

</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, wzpan

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>